package it.univaq.mwt.model.entity;


import java.io.Serializable;
import java.util.List;
import java.util.Set;


import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import javax.persistence.Id;
import javax.persistence.ManyToMany;

import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;

/*
 * --
-- Struttura della tabella `list`
--

CREATE TABLE IF NOT EXISTS `list` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `id_account` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

 */
@Entity
@NamedQueries({ 
	@NamedQuery(name="getListByIdList",query="SELECT l FROM Lists l WHERE l.id=:id_list"),
	@NamedQuery(name="getListByIdUser",query="SELECT l FROM Lists l WHERE l.user.idUser=:id_user"),
})
@SequenceGenerator(name="sequence",sequenceName="MASTER.LIST_SEQ")
public class Lists implements Serializable  {
	
	@Id
	@GeneratedValue(generator="sequence")
    
	@Column(name="id_list",nullable=false,length=11)
	private int id;
	
	@Column(name="name",nullable=false,length=100)
	private String name;
	
	
	@ManyToMany(mappedBy="list",cascade = { CascadeType.MERGE, CascadeType.REMOVE,  CascadeType.REFRESH}, fetch = FetchType.LAZY)
	private Set<Gift> gift;
	
	@OneToOne(mappedBy="list",cascade = { CascadeType.MERGE, CascadeType.REMOVE,  CascadeType.REFRESH}, fetch = FetchType.LAZY)
	private Users user;
	
	public Users getUser() {
		return user;
	}
	public void setUser(Users user) {
		this.user = user;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	public Set<Gift> getGift() {
		return gift;
	}
	public void setGift(Set<Gift> gift) {
		this.gift = gift;
	}

}
